<script>
export default {
  name: 'menuGroup',
  props: {
    item: {
      type: Object,
      required: true,
    },
    activeId: {
      type: [String, Number],
      default: () => ''
    }
  },
  emits: ['check'],
  setup(props, {emit}) {
    function clickMenu() {
      if (props.activeId === props.item.id) return
      emit('check', props.item)
    }

    return {
      clickMenu,
    }
  },
}

</script>

<template>
  <div class="m-group-wrap" :class="[activeId === item.id ? 'active' : '']" @click="clickMenu">
    <div class="menu-line">
      <svg-icon icon="caret-down" class="chevron-icon"/>
    </div>
    <div class="m-header">
      <svg-icon icon="folder" class="folder-icon"/>
      <span class="m-title">{{ item.name }}</span>
    </div>
    <div class="m--child-list">
      <div class="child-item"></div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.m-group-wrap {
  padding: 2px 0 2px 15px;
  box-sizing: border-box;
  position: relative;
  margin-bottom: 6px;

  &:last-child {
    margin-bottom: 0;
  }

  --m-color: #3c4353;

  &.active {
    --m-color: #0c64eb;
  }

  .menu-line {
    position: absolute;
    left: 4px;
    top: 6px;
    transition: color .1s ease;

    .chevron-icon {
      font-size: 14px;
      color: var(--m-color)
    }
  }


  .m--child-list {
    position: relative;
    box-sizing: border-box;
    height: 50px;
    border: 1px solid red;
    margin-left: 2px;
    display: none;
  }

  .m-header {
    display: flex;
    align-items: center;
    padding: 4px 6px;
    color: var(--m-color);
    width: 100%;
    cursor: pointer;
    transition: color .1s ease;

    .folder-icon {
      font-size: 18px;
    }

    .m-title {
      flex: 1;
      margin-right: 10px;
      font-size: 14px;
      margin-left: 4px;
      white-space: nowrap;
      position: relative;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>
